home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr37
/
satsfaxt.zip
/
CCPUTILS.ZIP
/
CCDEL.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-01-30
|
12KB
|
285 lines
/*---------------------------------------------------------------------------*
* CCDEL.C *
*---------------------------------------------------------------------------*
* This program allows the user to delete files from the Task and Log *
* queues. Options allow for the deletion of all errors, individual *
* jobs, or all jobs. *
* *
* The following source code is intended to assist developers in *
* creating applications which support the DCA/Intel Communicating *
* Applications Specification Version 1.0A. It is provided free of charge *
* and on an as-is basis. THE IMPLIED WARRENTIES OF MERCHANTABILITY AND *
* FITNESS FOR A PARTICULAR PURPOSE ARE SPECIFICALLY EXCLUDED. This source *
* code may be modified, enhanced, copied and distributed with applications *
* that support CAS on a royalty free basis. *
*---------------------------------------------------------------------------*
* History: Initial release 9/14/89. *
*===========================================================================*/
#include <stdio.h>
#include <dos.h>
#include <io.h>
#include <malloc.h>
#include "cas.h" /* Intel CAS header file. */
#include "parse.h" /* Command line parser header file. */
#include "util.h" /* CAS utilities header file. */
int AllFiles = FALSE; /* Delete all control files. */
int AllErrors = FALSE; /* Delete all control files with errors. */
char *JobNo = "0"; /* Delete a single job. */
unsigned long EventNo = 0; /* Converted Job number. */
int Verbose = FALSE; /* Echo job#'s as they are deleted. */
int Confirm = FALSE; /* Confirm deletion of control files. */
int Help = FALSE; /* Show help text. */
int RedirOut = FALSE; /* Redirect output to file. */
int EventDeleted = FALSE; /* Set TRUE if event deleted. */
ECF *TCFbuffer; /* Task Control File buffer. */
FILE *ccout; /* Redirected stdout file. */
STABLE SwitchTable[] = /* Command line parser switch table. */
{
{ 'A', BOOL, &AllFiles },
{ 'a', BOOL, &AllFiles },
{ 'C', BOOL, &Confirm },
{ 'c', BOOL, &Confirm },
{ 'L', BOOL, &AllErrors },
{ 'l', BOOL, &AllErrors },
{ 'E', STRING, (int *)&JobNo },
{ 'e', STRING, (int *)&JobNo },
{ 'N', BOOL, &Verbose },
{ 'n', BOOL, &Verbose },
{ 'R', BOOL, &RedirOut },
{ 'r', BOOL, &RedirOut },
{ '?', BOOL, &Help }
};
#define TABLESIZE (sizeof(SwitchTable)/sizeof(STABLE))
char *DescTable[] = /* Help function text table. */
{
"CCDEL (V1.0) Deletes files from the receive and log queues.\n\n",
"The options let you delete errors (/L), individual events (/E),\n",
"or all (/A) files.\n\n",
"Syntax: CCDEL [option...]\n\n"
};
#define DESCSIZE (sizeof(DescTable)/sizeof(DescTable[0]))
char *HelpTable[] = /* Help function text table. */
{
" /A Delete all files from the receive and log queues.\n",
" /E<number> Delete all files associated with the event specified\n"
" by <number>.\n",
" /L Delete all errors from the log queue.\n\n",
" /C Confirm before deletetion.\n",
" /N Notify by listing events as they're deleted.\n\n",
" /R Redirect output to file OUTPUT.CC.\n",
" /? Display help information.\n"
};
#define HELPSIZE (sizeof(HelpTable)/sizeof(HelpTable[0]))
/*---------------------------------------------------------------------------*
* GetTaskBuffer() *
*---------------------------------------------------------------------------*
* Get information about the specified task (Handle contains the job number).*
* On return, TCFbuffer is filled with the Task Conrol File information. *
*---------------------------------------------------------------------------*
* Parameters: int Handle - Event handle to return information from. *
* BYTE Queue - The queue (Task, Log or Receive) to return info *
* from. *
* char *TCFbuffer - Uninitialized ECF structure, filled with *
* task info on return. *
* int *FileHandle - Filled with DOS file handle on return. *
* Return: none *
*---------------------------------------------------------------------------*/
GetTaskBuffer(int Handle, BYTE Queue, char *TCFbuffer, int *FileHandle)
{
/* Open the Task Control File and read in the TCF portion of it. */
if((*FileHandle = CASOpenFile(Handle, 0, Queue)) > 0) {
read(*FileHandle, TCFbuffer, sizeof(ECF));
}
else
CASError(CASNOTCF, TRUE, -(*FileHandle));
}
/*---------------------------------------------------------------------------*
* DeleteAll() *
*---------------------------------------------------------------------------*
* Delete all entries that terminated due to errors. If confirmation asked *
* from command line, query user before deleting. If verbose specified, *
* notify user but don't querey before delete. *
*---------------------------------------------------------------------------*
* Paramters: ECF *TCFbuffer - Uninitialized ECF structure. *
* BYTE Queue - Which queue to delete from - RECEIVE or LOG. *
* Return: none *
*---------------------------------------------------------------------------*/
int DeleteAll(ECF *TCFbuffer, BYTE Queue)
{
int EventHandle; /* Event handle from FindFirst/Next. */
/* Find the first event with errors. */
EventHandle = CASFindFirst(ANY_STATUS, SEARCH_FORWARD, Queue);
while(EventHandle > 0) {
/* Determine which events to delete. */
if(AllFiles)
DeleteJob(EventHandle, TCFbuffer, Queue);
else if(AllErrors)
DeleteError(EventHandle, TCFbuffer, Queue);
/* Find the next error, additional parameters are remembered from the
* CASFindFirst call above. */
EventHandle = CASFindNext(Queue);
}
}
/*----------------------------------------------------------------------------*
* DeleteJob() *
*----------------------------------------------------------------------------*
* Delete a specified job. The control file and all associated files are *
* removed from the queue. *
*----------------------------------------------------------------------------*
* Parameters: int EventHandle - Event handle to delete. *
* ECF *TCFbuffer - Uninitialized ECF structure. *
* Return: none *
*----------------------------------------------------------------------------*/
DeleteJob(int Event, ECF *TCFbuffer, BYTE Queue)
{
int FileHandle; /* DOS file handle (from GetTaskBuffer). */
char answer[1]; /* Users response to confirmation quest. */
/* Get information about the Task. Don't forget to close the file. */
GetTaskBuffer(Event, Queue, (char *)TCFbuffer, &FileHandle);
close(FileHandle);
/* If requested, be verbose/confirm request. */
if(Verbose | Confirm) {
EventDeleted = TRUE;
fprintf(stdout, "Event Number %d (%s queue entry).\n", Event, (Queue == 1) ? "Receive" : "Log");
if(Confirm) {
fprintf(stderr, "Delete event (y/n)? ");
gets(answer);
}
if((Confirm && (toupper(answer[0]) == 'Y')) || (!Confirm))
if(CASDeleteFile(Event, 0, Queue) == SUCCESS)
fprintf(stdout, "Job deleted.\n");
else
CASError(CASDELJOB, FALSE, 0);
}
else
if(CASDeleteFile(Event, 0, Queue) == SUCCESS)
EventDeleted = TRUE;
else
CASError(CASDELJOB, FALSE, 0);
}
/*---------------------------------------------------------------------------*
* DeleteError() *
*---------------------------------------------------------------------------*
* Routine to delete errored events from the log or receive queue. *
* Information about each event is retrieved from the queue - if it *
* is logged as an error or was aborted, then it is removed from the queue *
* (user asked for confirmation if specified on the command line. *
*---------------------------------------------------------------------------*
* Parameters: int Event - Event handle to remove. *
* ECF *TCFbuffer - Task control file information. *
* BYTE Queue - Which queue to delete from (LOG or RECEIVE). *
*---------------------------------------------------------------------------*/
DeleteError(int Event, ECF *TCFbuffer, BYTE Queue)
{
int FileHandle; /* DOS file handle (from GetTaskBuffer). */
char answer[1]; /* Users response from confirmation ques.*/
/* Get information about the Task. Don't forget to close the file. */
GetTaskBuffer(Event, LOG_QUEUE, (char *)TCFbuffer, &FileHandle);
close(FileHandle);
/* Less than COMPLETED is an error, aborted is not really an error but... */
if((TCFbuffer->EventStatus < COMPLETED) || (TCFbuffer->EventStatus == ABORTED)) {
if(Verbose | Confirm) {
EventDeleted = TRUE;
fprintf(stdout, "Event Number %d (%s queue entry).\n", Event, (Queue == 1) ? "Receive" : "Log");
if(Confirm) {
fprintf(stderr, "Delete event (y/n)? ");
gets(answer);
}
if((Confirm && (toupper(answer[0]) == 'Y')) || (!Confirm))
if(CASDeleteFile(Event, 0, Queue) == SUCCESS)
fprintf(stdout, "Event deleted.\n");
else
CASError(CASDELJOB, FALSE, 0);
}
else
if(CASDeleteFile(Event, 0, Queue) == SUCCESS)
EventDeleted = TRUE;
else
CASError(CASDELJOB, FALSE, 0);
}
}
/*---------------------------------------------------------------------------*
* Main *
*---------------------------------------------------------------------------*
* Delete specified files from the Intel Connection CoProcessor queue. The *
* normal use is to specify a job number with the /J switch. All files can *
* be deleted using the /A switch and all errors with the /E switch. *
*---------------------------------------------------------------------------*
* Return: The DOS exit code is 0 if no errors are encountered, 1 for *
* commandline syntax errors, 2 for CCAM error, and 3 for DOS *
* errors. *
*---------------------------------------------------------------------------*/
main(int argc, char **argv)
{
int result; /* DOS & CAS function return values. */
argc = ParseCommand(argc, argv, SwitchTable, TABLESIZE);
/* Convert the event number to a long. */
EventNo = atol(JobNo);
/* If help is wanted, print info and exit (with 0 exit code). */
if(Help || (argc < 1))
CASHelp(DescTable, DESCSIZE, HelpTable, HELPSIZE);
/* Insure that the Resident Scheduler is installed. */
if((result = CASGetInstalledState()) != INSTALLED) {
if( result == NOTiOK )
CASError(CASNOHWO, TRUE, 0);
else
CASError(CASNOHWN, TRUE, 0);
}
/* Redirect stdout to a file. */
if(RedirOut) {
if((ccout = fopen("OUTPUT.CC", "w")) == NULL)
CASError(CASOPENTEMP, TRUE, 0);
if(-1 == dup2(fileno(ccout), 1))
CASError(CASBADREDIR, TRUE, 0);
}
/* Get buffer for Task information. */
TCFbuffer = (ECF *)malloc(sizeof(ECF));
if(TCFbuffer == NULL)
CASError(CASNOMEM, TRUE, 0);
/* If job specified, delete it, otherwise delete all files or all
* errors depending on what switches were set on command line. */
if(EventNo > 0) {
DeleteJob(EventNo, TCFbuffer, LOG_QUEUE);
if(TCFbuffer->EventType == RECEIVE)
DeleteJob(EventNo, TCFbuffer, RECEIVE_QUEUE);
}
else if(AllFiles) {
DeleteAll(TCFbuffer, LOG_QUEUE);
if(TCFbuffer->EventType == RECEIVE)
DeleteAll(TCFbuffer, RECEIVE_QUEUE);
}
else if(AllErrors)
DeleteAll(TCFbuffer, LOG_QUEUE);
if(!EventDeleted)
fprintf(stderr, "No event to delete.\n");
exit(0);
}